<?php

namespace App\Http\Controllers\Api\V1;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Dingo\Api\Routing\Helpers;

class BaseController extends Controller
{
    use Helpers;
    //
    public function __construct(){}

    /**
     * returnArray 返回统一格式
     * 
     * @param string $data 返回的数据
     * @param int $code 返回码
     * @param string $message 返回信息
     * @return mixed
     */
    public function returnArray($data = '', $code = 200, $message = 'success')
    {
        $res = [
            'message' => $message,
            'status_code' => $code,
            'data' => $data
        ];
        return $this->response->array($res)->setStatusCode($code);
    }
    /**
     * csrf token
     * @return mixed
     */
    public function getCsrfToken(){

        return $this->returnArray(['content'=>csrf_token()]);
    }
    /**
     * returnValidate 返回验证失败格式
     *
     * @param string $data 返回的数据
     * @param int $code 返回码
     * @param string $message 返回信息
     * @return mixed
     */
    public function returnValidate($data = '', $code = 422, $message = 'validate fail')
    {
        $res = [
            'message' => $message,
            'status_code' => $code,
            'data' => $data
        ];
        return $this->response->array($res)->setStatusCode($code);
    }
}
